<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/jianyin.webp" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="myblog_list.html">我的文章</a>
        <a href="blog_add.html">写博客</a>
        <a href="javascript:logout()">注销</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="img/jianyin1.webp" class="avtar" alt="">
                <h3 id="username"></h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span id="artCount">2</span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div id="artDiv" class="container-right">
            <!-- 每一篇博客包含标题, 摘要, 时间 -->
            
        </div>
    </div>

    <script>
        function showInfo() {
            jQuery.ajax({
                url:"/user/showinfo",
                type:"POST",
                data:{},
                success:function(result) {
                    if(result != null && result.code == 200) {
                        jQuery("#username").text(result.data.username);
                        jQuery("#artCount").text(result.data.artCount);
                    } else {
                        alert("个人信息加载失败！");
                    }
                }
            })
        }
        showInfo();
        function getMyArtListDraft() {
            jQuery.ajax({
                url:"/art/listdraft",
                type:"POST",
                data:{},
                success:function(result) {
                    if(result != null && result.code == 200) {
                        if(result.data != null && result.data.length > 0) {
                            
                            var artListDiv = "";
                            for(var i = 0; i < result.data.length;i++) {
                                var artItem = result.data[i];
                                artListDiv += '<div class="blog">';
                                artListDiv += '<div class="title">'+ artItem.title+'</div>';
                                artListDiv += '<div class="date">'+ artItem.updatetime+'</div>';
                                artListDiv += '<div class="desc">';
                                artListDiv += artItem.content;
                                artListDiv += ' </div>';
                                artListDiv += '<a href="blog_content.html?id='+ 
                                    artItem.id +'" class="detail">查看草稿 &gt;&gt;</a>&nbsp;&nbsp;';
                                artListDiv += ' <a href="blog_edit_draft.html?id='+ 
                                    artItem.id +'" class="detail">继续编写 &gt;&gt;</a>&nbsp;&nbsp;';
                                artListDiv += '<a href="javascript:myDel('+ 
                                    artItem.id +')" class="detail">删除 &gt;&gt;</a>&nbsp;&nbsp;';
                                artListDiv += '</div>';
                            }
                            jQuery("#artDiv").html(artListDiv);
                        }else {
                            jQuery("#artDiv").html("<h3>暂无文章~</h3>");
                        }
                    } else {
                        alert("查询文章失败！");
                    }
                }
            })
        }
        getMyArtListDraft();

        function myDel(id) {
            if(confirm("确认删除？")) {
                jQuery.ajax({
                url:"art/del",
                type:"POST",
                data:{"id":id},
                success:function(result) {
                    if(result != null && result.code ==200 && result.data == 1) {
                        alert("删除成功！");
                        location.href = location.href;
                    } else {
                        alert("删除失败！");
                    }
                }
            });
            }
        }
        function logout() {
            if(confirm("确认退出？")) {
                jQuery.ajax({
                    url:"/user/logout",
                    type:"POST",
                    data:{},
                    success:function(result) {
                        if(result != null && result.code ==200) {
                            location.href = "/login.html";  
                        }
                    }
                });
            }
        }
    </script>
</body>

</html>